//
// Cube.cpp for cube in /tmp/noboa-y-global/yn
//
// Made by maxime marie
// Login   <marie_m@epitech.net>
//
// Started on  Fri Apr 20 15:04:13 2012 maxime marie
// Last update Wed May  2 15:37:12 2012 youri noboa
//

#include	<GL/gl.h>
#include	<GL/glu.h>
// #include	<Image.hpp>
// #include	<TextureMgr.hpp>
#include	"Cube.hh"

namespace	Object
{
  void		Cube::initialize(void)
  {
    // this->texture_ = gdl::Image::load("../assets/textures/simple-caisse-en-bois.jpg");
  }

  void		Cube::update(const gdl::GameClock &gameClock, gdl::Input &input)
  {
    (void)gameClock;
    if (input.isKeyDown(gdl::Keys::Right))
      this->rotation_.y = ((int)rotation_.y + 10) % 360;
    if (input.isKeyDown(gdl::Keys::Left))
      this->rotation_.y = ((int)rotation_.y - 10) % 360;
    if (input.isKeyDown(gdl::Keys::Up))
      this->rotation_.x = ((int)rotation_.x - 10) % 360;
    if (input.isKeyDown(gdl::Keys::Down))
      this->rotation_.x = ((int)rotation_.x + 10) % 360;
  }

  void		Cube::draw(void)
  {
    float	h = 600.0f;
    float	p = 1000.0f;
    float	w = 400.0f;
    float	x = -600.0f;
    float	y = 0.f;
    float	z = -900.0f;

    glPushMatrix();
    glLoadIdentity();
    glTranslatef(x, y, z);
    glRotatef(this->rotation_.y, 0.0f, 1.0f, 0.0f);
    glRotatef(this->rotation_.x, 1.0f, 0.0f, 0.0f);

    glBegin(GL_QUADS);

    //face

    glColor3f(1.0f, 0.50f, 0.75f);
    // glTexCoord2f(0.0f, 0.0f);
    glVertex3f(-w, h, 0.0f);
    // glTexCoord2f(0.0f, 1.0f);
    glVertex3f(-w, 0.0f, 0.0f);
    // glTexCoord2f(1.0f, 1.0f);
    glVertex3f(0.0f, -0.0f, 0.0f);
    // glTexCoord2f(1.0f, 0.0f);
    glVertex3f(0.0f, h, 0.0f);

    //back

    glColor3f(0.0f, 0.0f, 1.0f);
    glVertex3f(-w, h, -p);
    glVertex3f(-w, -0.0f, -p);
    glVertex3f(-w, -0.0f, 0.0f);
    glVertex3f(-w, h, 0.0f);

    //left

    glColor3f(0.0f, 1.0f, 0.0f);
    glVertex3f(0.0f, h, -p);
    glVertex3f(0.0f, -0.0f, -p);
    glVertex3f(-w, -0.0f, -p);
    glVertex3f(-w, h, -p);

    //right

    glColor3f(1.0f, 0.0f, 0.0f);
    glVertex3f(0.0f, h, 0.0f);
    glVertex3f(0.0f, -0.0f, 0.0f);
    glVertex3f(0.0f, -0.0f, -p);
    glVertex3f(0.0f, h, -p);

    //top

    glColor3f(1.0f, 1.0f, 1.0f);
    glVertex3f(-w, h, 0.0f);
    glVertex3f(-w, h, -p);
    glVertex3f(0.0f, h, -p);
    glVertex3f(0.0f, h, 0.0f);

    //bottom

    glColor3f(0.0f, 0.0f, 0.0f);
    glVertex3f(0.0f, -0.0f, 0.0f);
    glVertex3f(-w, -0.0f, 0.0f);
    glVertex3f(-w, -0.0f, -p);
    glVertex3f(0.0f, -0.0f, -p);

    glEnd();
  }
}
